//
//  PictureCollectionView.swift
//  LCYWeiBo
//
//  Created by 李长友 on 16/9/7.
//  Copyright © 2016年 app. All rights reserved.
//

import UIKit

class PictureCollectionView: UICollectionView {

    var dataArray : [NSURL] = [] {
        didSet {
            self.reloadData()
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        dataSource = self
        
        self.registerClass(PictureCollectionViewCell.classForCoder(), forCellWithReuseIdentifier: "pictureCell")
    }
    
}

extension PictureCollectionView: UICollectionViewDataSource {
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return dataArray.count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("pictureCell", forIndexPath: indexPath) as! PictureCollectionViewCell
        
        cell.picImageView.sd_setImageWithURL(dataArray[indexPath.row], placeholderImage: UIImage(named: "empty_picture"))
        
        return cell
    }
}

class PictureCollectionViewCell: UICollectionViewCell {
    
    var picImageView : UIImageView = UIImageView()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        picImageView.frame = self.bounds
        self.addSubview(picImageView)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}




















